package me.xingyannian.hope.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import java.util.Set;

@Getter
@Setter
@Entity
@Table(name = "hope_user")
public class User extends BaseEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id", nullable = false)
    private Long id;

    private String name;

    @Column(unique = true)
    private String loginId;

    @NotNull
    @JsonIgnore
    private String password;

    private String gender;

    private String phone;

    @Email
    private String email;

    private Boolean enabled;

    @Column(name = "last_login_time")
    @JsonIgnore
    private Timestamp lastLoginTime;

    @Column(name = "last_login_ip")
    @JsonIgnore
    private String lastLoginIp;

    @OneToOne
    @JoinColumn(name = "dept_id")
    private Dept dept;

    @ManyToMany(fetch = FetchType.EAGER)
    @JsonIgnore
    @JoinTable(name = "hope_user_role",
            joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
    private Set<Role> roles;

    @ManyToMany
    @JsonIgnore
    @JoinTable(name = "hope_user_job",
            joinColumns = {@JoinColumn(name = "user_id",referencedColumnName = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "job_id",referencedColumnName = "job_id")})
    private Set<Job> jobs;

}